#include "hm_util.h"
#include <EIKENV.H>

extern CHtmlControl* gHtmlControl;
ChmUtil::ChmUtil()
{
}

ChmUtil::~ChmUtil()
{
}

void ChmUtil::HideDiv(const TDesC& div, bool refresh)
{
	if(gHtmlControl == NULL) return;
	CHtmlElement* itemcontainer = gHtmlControl->Element(div);
	if(itemcontainer == NULL) return;
	itemcontainer->SetStyle(KHStrDisplay, KHStrNone);	
	
	if(refresh)
		gHtmlControl->RefreshAndDraw();	
}

void ChmUtil::ShowDiv(const TDesC& div, bool refresh)
{
	if(gHtmlControl == NULL) return;
	CHtmlElement* itemcontainer = gHtmlControl->Element(div);
	if(itemcontainer == NULL) return;
	itemcontainer->SetStyle(KHStrDisplay, KHStrVisible);	
	
	if(refresh)
		gHtmlControl->RefreshAndDraw();	
}

bool ChmUtil::IsDivVisible(const TDesC& divname)
{
	if(gHtmlControl == NULL) return false;
	CHtmlElement* itemcontainer = gHtmlControl->Element(divname);
	if(itemcontainer == NULL) return false;
	TBuf<20> displayed;
	itemcontainer->GetStyle(KHStrDisplay, displayed);
	if(displayed == _L("none")) return false;
	return true;
}

//based on the situation of menubar and apptab
void ChmUtil::AdjustClientHeight()
{
	int height = _fullclientheight; 
	int offset = 0;
	if(IsDivVisible(_L("iMenuBar")))
		offset += _menubarheight;
	if(IsDivVisible(_L("iTopTab")))
		offset += _apptabheight;
	height = _fullclientheight - offset;
	
	if(_clientheight == height)
	return;
	
	TBuf<10> hi;
	hi.Num(height);
	CHtmlElement* itemcontainer = gHtmlControl->Element(_L("iContent"));
	if(itemcontainer == NULL) return;
	itemcontainer->SetStyle(KHStrHeight, hi);
	_clientheight = height;
}
